﻿namespace YmtAuth.Dto
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// 服务端响应消息
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ResponseData<T>
    {        
        public string LastErrorMessage { get; set; }       
        public string ErrorCode { get; set; }
        public bool Success { get; set; }
        public T Result { get; set; }

        public static ResponseData<T> CreateSuccess(T val,string message=null)
        {
            return new ResponseData<T>
            {
                Success = true,
                Result = val,
                LastErrorMessage = message            
            };
        }

        public static ResponseData<T> CreateFail(T val, string errorCode="", string lastErrorMessage="")
        {
            return new ResponseData<T>
            {
                Success = false,
                Result = val,
                ErrorCode = errorCode,
                LastErrorMessage = lastErrorMessage,
               
            };
        }

        public static ResponseData<T> Create(T val, bool success, string lastErrorMessage="", string errorCode="")
        {
            return new ResponseData<T>
            {
                Success = success,
                Result = val,
                LastErrorMessage = lastErrorMessage,
                ErrorCode = errorCode,               
            };
        }     
    }
}
